//
//  WDGoutServiceCancelView.m
//  wd-serviceapp
//
//  Created by Bin Tang on 2025/3/28.
//

#import "WDGoutServiceCancelView.h"
#import "WDArrivalServiceDetailModel.h"

@interface WDGoutServiceCancelView ()

@property (nonatomic, strong) WDArrivalServiceDetailModel *taskDetailModel;

/// 关闭/取消原因
@property (nonatomic, strong) WDTaskDetailBasicSingleView *contentView;

/// 处理时间
@property (nonatomic, strong) WDTaskDetailBasicSingleView *handleTimeView;

/// 处理账号
@property (nonatomic, strong) WDTaskDetailBasicSingleView *handleAccountView;


/// 关闭/取消原因
- (void)initWithContentView;

/// 处理时间
- (void)initWithHandleTimeView;

/// 处理账号
- (void)initWithHandleAccountView;

@end

@implementation WDGoutServiceCancelView


- (void)initWithSubView {
    [super initWithSubView];
    
    self.backgroundColor = [UIColor whiteColor];
    
    CGRect frame = CGRectMake(20, 0, self.width - 40, 1);
    [CALayer drawLine:self frame:frame lineColor:[UIColor colorWithHexString:@"#DDDDDD"]];
}

/// 关闭/取消原因
- (void)initWithContentView {
    float height = 10 + self.taskDetailModel.cancel.contentHeight;
    if (!_contentView) {
        CGRect frame = CGRectMake(0, 0, self.width, height);
        _contentView = [[WDTaskDetailBasicSingleView alloc] initWithFrame:frame];
        [self addSubview:_contentView];
    }
    if (self.taskDetailModel) {
        NSString *title = @"关闭原因";
        // source 来源 0.用户 1.客服 2.工程师
        NSString *content = self.taskDetailModel.cancel.content;
        if (self.taskDetailModel.cancel.source == 0) {
            title = @"取消原因";
        } else if (self.taskDetailModel.cancel.source == 1) {
            content = @"后台关闭";
        }
        [_contentView updateWithViewTitle:title value:objectNull(content) valueHeight:self.taskDetailModel.cancel.contentHeight];
    }
}

/// 处理时间
- (void)initWithHandleTimeView {
    if (!_handleTimeView) {
        CGRect frame = CGRectMake(0, self.contentView.bottom, self.width, kWDTaskDetailBasicSingleViewHeight);
        _handleTimeView = [[WDTaskDetailBasicSingleView alloc] initWithFrame:frame];
        [self addSubview:_handleTimeView];
    }
    if (self.taskDetailModel) {
        NSString *str = objectNull(self.taskDetailModel.cancel.createTime);
        [_handleTimeView updateWithViewTitle:@"处理时间" value:str valueHeight:18];
    }
}

/// 处理账号
- (void)initWithHandleAccountView {
    if (!_handleAccountView) {
        CGRect frame = self.handleTimeView.frame;
        frame.origin.y = self.handleTimeView.bottom;
        _handleAccountView = [[WDTaskDetailBasicSingleView alloc] initWithFrame:frame];
        [self addSubview:_handleAccountView];
    }
    if (self.taskDetailModel) {
        NSString *str = objectNull(self.taskDetailModel.cancel.createUserName);
        [_handleAccountView updateWithViewTitle:@"处理账号" value:str valueHeight:18];
    }
}


- (void)updateWithViewData:(id)data {
    self.taskDetailModel = data;
    
    /// 关闭/取消原因
    [self initWithContentView];

    /// 处理时间
    [self initWithHandleTimeView];

    if (self.taskDetailModel.cancel.source != 0) {
        /// 处理账号
        [self initWithHandleAccountView];
    }
    

}

@end
